<?php include_partial('task/css') ?>
<script type="text/javascript" src="/js/sprints.js"></script>
<style>
.ria-list {
    background-color: #fff;
    width: 300px;
    height: 500px;
    overflow: auto;
    border: solid 1px;
    padding: 10px;
}
</style>
<script>
    $(document).ready(function() {
        sprints.data = <?php echo json_encode($sprints) ?>;
        $(document).ready(function() {
            sprints.newItem = ria.buildItem()
            .setJsObjName('sprints.newItem')
            .setDs(<?php $p = new Sprint(); echo json_encode($p->toArray()) ?>)
            .setElement($('#new'))
            .setTpls({
                view: "<?php echo $sprintViewTpl ?>",
                form: "<?php echo $sprintFormTpl ?>"
            })
            .setDecorators({
                edit: "<?php echo $editDecorator ?>",
                insert: "<?php echo $insertDecorator ?>",
                view: "<?php echo $viewDecorator ?>"
            })
            .setViews({
                view:   {tpl:'view',decorator:'view'},
                edit:   {tpl:'form',decorator:'edit'},
                insert: {tpl:'form',decorator:'insert'}
            })
            .setExtraTplValue('_objRequestName','sprint')
            .setExtraTplValue('_formId','form-new-sprint')
            .setActualView('insert')
            .bind('postDisplay', function(spec){this.markCheckboxes();});

            //DUPLICA CONFIGURAÇÕES DO NOVO ITEM PARA USAR COMO ITEM DA LISTA.
            var listItem = sprints.newItem.copy();
            //ADICIONA COMANDOS EXTRAS À LISTA.
            listItem.addCommand('mouseOver', function(spec, params){
               this.getElement().addClass('itemHover');
            }).addCommand('mouseOut', function(spec, params){
                this.getElement().removeClass('itemHover');
            }).addCommand('clickItem', function(spec, params){
                JsonC.callSfAction('sprints/show',{id:spec.ds.id},'general-loading');
            });
            //ADICIONA COMANDOS RELEVANTES À AMBOS. SE ADICIONAR ANTES OS COMANDOS, ESTÁ DANDO PROBLEMA.
            ria.addItemCommands([sprints.newItem,listItem],
                {
                    insertAction:'sprints/insert',
                    editAction:'sprints/edit',
                    removeAction:'sprints/remove'
                }
            );

            sprints.list = ria.buildList()
            .setJsObjName('sprints.list')
            .setDs({listId:"sprints-list"})
            .setItemId('sprints-list-item-')
            .setItemsDs(sprints.data)
            .setElement($('#local'))
            .setRiaObject(listItem.setActualView('view'))
            .setExtraItemTplValues({
                _jsObjName : 'sprints.list.getItem(${dsId})',
                _objRequestName : 'sprint',
                _formId : 'form-sprint-${dsId}'
            })
            .setTpls({list: "<?php echo $listTpl ?>"})
            .setItemDecorators({div: "<?php echo $divListItemDecorator ?>"})
            .setViews({list:  {tpl:'list',itemDecorator:'div'}})
            .display('list');
            ria.addListCommands([sprints.list]);
        });

    });
</script>
<style>
#container{
    width: 1100px;
    height: 500px;
    overflow: auto;
    border: solid 1px;
    padding: 10px;
}
.dirFound{
   background-color: #beb;
}
.dirNotFound{
   background-color: #ebb;
}
</style>
<h3>sprints</h3>
<button type='button' onclick="sprints.newItem.showOnDialog({view:'insert'})"/>create a new sprint</button>
<table>
    <tr>
        <td valign="top">
            <div id='local'></div>
        </td>
        <td valign="top">
            <div id='sprint'></div>
        </td>
    </tr>
</table>